package com.learning.netease.optimize.trx.orderservice.dao;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * ClassName: OrderDao
 * Description:
 * Date: 2019/1/30 14:55 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Repository
public class OrderDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    public void saveOrder(JSONObject orderInfo) throws Exception {
        String orderId = orderInfo.getString("orderId");
        String userId = orderInfo.getString("userId");
        String orderContent = orderInfo.getString("orderContent");
        Date createTime = orderInfo.getDate("createTime");
        
        String sql = "insert into t_order values (?,?,?,?)";

        int res = jdbcTemplate.update(sql, orderId, userId, orderContent, createTime);
        if (res != 1) {
            throw new Exception("订单创建失败，原因【数据库操作失败】");
        }
    }
}
